﻿using System.Collections.Generic;
using System.Data;
using System;

namespace ZHDJ.MobileInterface
{
    public partial class GetCheckAccount : AbstractBasePage
    {
        protected override OutParam BusinessProcess<InParam, OutParam>(InParam inParam)
        {
            // 业务逻辑返回的响应对象  
            CheckAccountOutParam result = new CheckAccountOutParam();
            CheckAccountInParam param = new CheckAccountInParam();
            string logMsg = "";
            bool isFlag = true;

            try
            {
                param = inParam as CheckAccountInParam;

                string url = CommonUtils.AppAddressNote + "WS/PartySmsCheckService.asmx";
                PartySmsCheckService service = new PartySmsCheckService(url);
                if (!string.IsNullOrEmpty(param.mobile))
                {
                    param.mobile = param.mobile.Trim();
                    if (!service.CheckMobileUnique(param.mobile))
                    {
                        result.code = "0";
                        result.desc = "你输入的手机号码：" + param.mobile + " 已经存在，请更改后重新注册！";

                        isFlag = false;
                    }
                }

                //if (isFlag)
                //{
                //    isFlag = service.CheckDynamicCode(param.mobile, "RegisterCheck", param.vcode);

                //    if (!isFlag)
                //    {
                //        result.code = "0";
                //        result.desc = "验证码不正确！";
                //    }
                //}

                if (!string.IsNullOrEmpty(param.idcard))
                {
                    param.idcard = param.idcard.Trim();
                    if (InterfaceHelper.CheckIdentityCardIsExists(param.idcard))
                    {
                        result.code = "0";
                        result.desc = "你输入的身份证号码：" + param.idcard + " 已经存在，请更改后重新注册！";

                        isFlag = false;
                    }
                }
                if (!string.IsNullOrEmpty(param.cname))
                {
                    param.cname = param.cname.Trim();
                    if (InterfaceHelper.CheckName(param.cname))
                    {
                        result.code = "0";
                        result.desc = "你输入的姓名：" + param.cname + " 已经存在，请更改后重新注册！";

                        isFlag = false;
                    }
                }

                if (!string.IsNullOrEmpty(param.user_name))
                {
                    param.user_name = param.user_name.Trim();

                    if (InterfaceHelper.CheckLoginIDCount(param.user_name))
                    {
                        result.code = "0";
                        result.desc = "你输入的用户名：" + param.user_name + " 已经存在，请更改后重新注册！";

                        isFlag = false;
                    }
                    if (InterfaceHelper.CheckLoginIDCountEx(param.user_name))
                    {
                        result.code = "0";
                        result.desc = "你输入的用户名：" + param.user_name + " 已经存在，请更改后重新注册！";

                        isFlag = false;
                    }
                }

                logMsg = result.desc;
            }
            catch (Exception ex)
            {
                result.code = "0";
                result.desc = "操作异常，多次出现请联系管理员";
                logMsg = ex.Message + ":" + ex.StackTrace;
            }

            CommonUtils.InsertMobileInterfaceLog(SystemCode + "-GetCheckAccount", SerializeHelper.JsonSerializer<CheckAccountInParam>(param), logMsg);
            return result as OutParam;
        }

        protected void Page_Load(object sender, System.EventArgs e)
        {
            if (string.Compare(Request.QueryString["Safe"], "False", true) == 0)
                ProcessRequest<CheckAccountInParam, CheckAccountOutParam>();
            else
                SafeProcessRequest<CheckAccountInParam, CheckAccountOutParam>();
        }
    }
    #region 请求参数
    public class CheckAccountInParam
    {
        /// <summary>
        ///	用户名	必须
        /// </summary>
        public string user_name
        { get; set; }
        /// <summary>
        ///	身份证号	
        /// </summary>
        public string idcard
        { get; set; }
        /// <summary>
        ///	姓名	 用户真实姓名，中文汉字（必填）
        /// </summary>
        public string cname
        { get; set; }
        /// <summary>
        ///	手机号码	
        /// </summary>
        public string mobile
        { get; set; }
    }
    #endregion

    #region 结果参数
    public class CheckAccountOutParam
    {
        public CheckAccountOutParam()
        {
            code = "1";
            desc = "操作成功";
        }

        /// <summary>
        /// 返回结果 具体见接口返回对照码 1	成功 0	失败 2	请求非法 加密结果和传入的MD5字符串进行比较，如果相同则执行接口操作，否则返回1001错误响应码
        /// </summary>
        public string code
        { get; set; }

        /// <summary>
        /// 结果描述 成功和失败都需要
        /// </summary>
        public string desc
        { get; set; }
    }
    #endregion
}